package com.ruoyi.web.controller.ora;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.enums.dict.SysYesNo;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ora.domain.UserMessage;
import com.ruoyi.ora.service.IUserMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息Controller
 * 
 * @author liuwp
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/ora/user_message")
public class UserMessageController extends BaseController
{
    @Autowired
    private IUserMessageService userMessageService;

    /**
     * 查询消息列表
     */
    @PreAuthorize("@ss.hasPermi('ora:user_message:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserMessage userMessage)
    {
        startPage();
        List<UserMessage> list = userMessageService.selectUserMessageList(userMessage);
        return getDataTable(list);
    }

    /**
     * 导出消息列表
     */
    @PreAuthorize("@ss.hasPermi('ora:user_message:export')")
    @Log(title = "消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserMessage userMessage)
    {
        List<UserMessage> list = userMessageService.selectUserMessageList(userMessage);
        ExcelUtil<UserMessage> util = new ExcelUtil<UserMessage>(UserMessage.class);
        util.exportExcel(response, list, "消息数据");
    }

    /**
     * 获取消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ora:user_message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        UserMessage userMessage = userMessageService.selectUserMessageById(id);
        if (userMessage != null) {
            userMessage.setRealStatus(SysYesNo.YES.getValue());
            userMessageService.updateUserMessage(userMessage);
        }
        return AjaxResult.success(userMessageService.selectUserMessageById(id));
    }

    /**
     * 新增消息
     */
    @PreAuthorize("@ss.hasPermi('ora:user_message:add')")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserMessage userMessage)
    {
        return toAjax(userMessageService.insertUserMessage(userMessage));
    }

    /**
     * 修改消息
     */
    @PreAuthorize("@ss.hasPermi('ora:user_message:edit')")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserMessage userMessage)
    {
        return toAjax(userMessageService.updateUserMessage(userMessage));
    }

    /**
     * 删除消息
     */
    @PreAuthorize("@ss.hasPermi('ora:user_message:remove')")
    @Log(title = "消息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userMessageService.deleteUserMessageByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('ora:user_message:list')")
    @GetMapping("/query")
    public TableDataInfo query(UserMessage userMessage)
    {
        startPage();
        userMessage.setUserId(SecurityUtils.getUserId());
        List<UserMessage> list = userMessageService.selectUserMessageList(userMessage);
        return getDataTable(list);
    }
}
